#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include "client_init.h"
/*
 * 销毁客户端资源，释放所有分配的内存和网络资源
 * @param client 要销毁的Client指针
 */
void destroy(Client* client) {
    if (client == NULL) {
        printf("错误：销毁。指针为空\n");
    return;
    }


    // 关闭套接字连接
    if (client->socket_fd != -1) {
    close(client->socket_fd);
    }

    // 释放服务器IP内存
    if (client->server_ip) {
        free(client->server_ip);
        client->server_ip = NULL;
    }

    // 释放接收缓冲区
    if (client->recv_buffer) {
        free(client->recv_buffer);
        client->recv_buffer = NULL;
        client->buffer_size = 0;
    }

    // 释放客户端结构体本身
    free(client);
    printf("Client resources destroyed completely\n");
}

// 示例用法

